<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>珠峰架构师成长计划</title>
    <link rel="stylesheet" type="text/css" href="../static/css/main.css">
</head>
<body>
<div class="nav">
    <div class="logo">
        
            珠峰架构师成长计划
        
    </div>
<ul><li><a href="../index.html">0.Async</a></li><li><a href="../html/0.editor.html">0.editor</a></li><li><a href="../html/0.module.html">0.module</a></li><li><a href="../html/1.ES2015.html">1.ES2015</a></li><li><a href="../html/2.Promise.html">2.Promise</a></li><li><a href="../html/3.Node.html">3.Node</a></li><li><a href="../html/4.NodeInstall.html">4.NodeInstall</a></li><li><a href="../html/5.REPL.html">5.REPL</a></li><li><a href="../html/6.NodeCore.html">6.NodeCore</a></li><li><a href="../html/7.module&NPM.html">7.module&NPM</a></li><li><a href="../html/8.Encoding.html">8.Encoding</a></li><li><a href="../html/9.Buffer.html">9.Buffer</a></li><li><a href="../html/10.fs.html">10.fs</a></li><li><a href="../html/11.Stream-1.html">11.Stream-1</a></li><li><a href="../html/11.Stream-2.html">11.Stream-2</a></li><li><a href="../html/11.Stream-3.html">11.Stream-3</a></li><li><a href="../html/11.Stream-4.html">11.Stream-4</a></li><li><a href="../html/12-Network-2.html">12-Network-2</a></li><li><a href="../html/12.NetWork-3.html">12.NetWork-3</a></li><li><a href="../html/12.Network-1.html">12.Network-1</a></li><li><a href="../html/13.tcp.html">13.tcp</a></li><li><a href="../html/14.http-1.html">14.http-1</a></li><li><a href="../html/14.http-2.html">14.http-2</a></li><li><a href="../html/15.compress.html">15.compress</a></li><li><a href="../html/16.crypto.html">16.crypto</a></li><li><a href="../html/17.process.html">17.process</a></li><li><a href="../html/18.yargs.html">18.yargs</a></li><li><a href="../html/19.cache.html">19.cache</a></li><li><a href="../html/20.action.html">20.action</a></li><li><a href="../html/21.https.html">21.https</a></li><li><a href="../html/22.cookie.html">22.cookie</a></li><li><a href="../html/23.session.html">23.session</a></li><li><a href="../html/24.express-1.html">24.express-1</a></li><li><a href="../html/24.express-2.html">24.express-2</a></li><li><a href="../html/24.express-3.html">24.express-3</a></li><li><a href="../html/24.express-4.html">24.express-4</a></li><li><a href="../html/25.koa-1.html">25.koa-1</a></li><li><a href="../html/26.webpack-1-basic.html">26.webpack-1-basic</a></li><li><a href="../html/26.webpack-2-optimize.html">26.webpack-2-optimize</a></li><li class="active"><a href="../html/26.webpack-3.tapable.html">26.webpack-3.tapable</a></li><li><a href="../html/26.webpack-4-AST.html">26.webpack-4-AST</a></li><li><a href="../html/26.webpack-5-source.html">26.webpack-5-source</a></li><li><a href="../html/26.webpack-6-loader.html">26.webpack-6-loader</a></li><li><a href="../html/26.webpack-7-plugin.html">26.webpack-7-plugin</a></li><li><a href="../html/26.webpack-8-hand.html">26.webpack-8-hand</a></li><li><a href="../html/27.react-1.html">27.react-1</a></li><li><a href="../html/27.react-2.html">27.react-2</a></li><li><a href="../html/27.react-3.html">27.react-3</a></li><li><a href="../html/27.react-4-immutable.html">27.react-4-immutable</a></li><li><a href="../html/27.react-5-react-dom-diff.html">27.react-5-react-dom-diff</a></li><li><a href="../html/27.react-6.html">27.react-6</a></li><li><a href="../html/28.react-mobx.html">28.react-mobx</a></li><li><a href="../html/28.redux-0.html">28.redux-0</a></li><li><a href="../html/28.redux-1.html">28.redux-1</a></li><li><a href="../html/28.redux-2-中间件.html">28.redux-2-中间件</a></li><li><a href="../html/28.redux-3-saga.html">28.redux-3-saga</a></li><li><a href="../html/28.redux-jwt-back.html">28.redux-jwt-back</a></li><li><a href="../html/28.redux-jwt-front.html">28.redux-jwt-front</a></li><li><a href="../html/29.mongodb-1.html">29.mongodb-1</a></li><li><a href="../html/29.mongodb-2.html">29.mongodb-2</a></li><li><a href="../html/29.mongodb-3.html">29.mongodb-3</a></li><li><a href="../html/29.mongodb-4.html">29.mongodb-4</a></li><li><a href="../html/29.mongodb-5.html">29.mongodb-5</a></li><li><a href="../html/29.mongodb-6.html">29.mongodb-6</a></li><li><a href="../html/30.cms-1-mysql.html">30.cms-1-mysql</a></li><li><a href="../html/30.cms-2-mysql.html">30.cms-2-mysql</a></li><li><a href="../html/30.cms-3-mysql.html">30.cms-3-mysql</a></li><li><a href="../html/30.cms-4-egg.html">30.cms-4-egg</a></li><li><a href="../html/30.cms-5-api.html">30.cms-5-api</a></li><li><a href="../html/30.cms-6-roadhog.html">30.cms-6-roadhog</a></li><li><a href="../html/30.cms-7-umi.html">30.cms-7-umi</a></li><li><a href="../html/30.cms-8-dva.html">30.cms-8-dva</a></li><li><a href="../html/30.cms-9-dva.html">30.cms-9-dva</a></li><li><a href="../html/30.cms-10-front.html">30.cms-10-front</a></li><li><a href="../html/30.cms-11-deploy.html">30.cms-11-deploy</a></li><li><a href="../html/33.redis.html">33.redis</a></li><li><a href="../html/34.unittest.html">34.unittest</a></li><li><a href="../html/35.jwt.html">35.jwt</a></li><li><a href="../html/36.websocket-1.html">36.websocket-1</a></li><li><a href="../html/36.websocket-2.html">36.websocket-2</a></li><li><a href="../html/38.chat-api-1.html">38.chat-api-1</a></li><li><a href="../html/38.chat-api-2.html">38.chat-api-2</a></li><li><a href="../html/38.chat-3.html">38.chat-3</a></li><li><a href="../html/38.chat-api-3.html">38.chat-api-3</a></li><li><a href="../html/38.chat.html">38.chat</a></li><li><a href="../html/38.chat2.html">38.chat2</a></li><li><a href="../html/38.chat2.html">38.chat2</a></li><li><a href="../html/39.crawl-0.html">39.crawl-0</a></li><li><a href="../html/39.crawl-1.html">39.crawl-1</a></li><li><a href="../html/39.crawl-2.html">39.crawl-2</a></li><li><a href="../html/40.deploy.html">40.deploy</a></li><li><a href="../html/41.safe.html">41.safe</a></li><li><a href="../html/42.test.html">42.test</a></li><li><a href="../html/43.nginx.html">43.nginx</a></li><li><a href="../html/44.enzyme.html">44.enzyme</a></li><li><a href="../html/45.docker.html">45.docker</a></li><li><a href="../html/46.elastic.html">46.elastic</a></li><li><a href="../html/47.oauth.html">47.oauth</a></li><li><a href="../html/48.wxpay.html">48.wxpay</a></li><li><a href="../html/49.nunjucks.html">49.nunjucks</a></li><li><a href="../html/50.ketang.html">50.ketang</a></li><li><a href="../html/index.html">index</a></li><li><a href="../html/51.typescript.html">51.typescript</a></li><li><a href="../html/52.UML.html">52.UML</a></li><li><a href="../html/53.design.html">53.design</a></li><li><a href="../html/index.html">index</a></li><li><a href="../html/54.linux.html">54.linux</a></li><li><a href="../html/55.yaml.html">55.yaml</a></li><li><a href="../html/50.ketang2.html">50.ketang2</a></li><li><a href="../html/56.ts.html">56.ts</a></li><li><a href="../html/57.ts_react.html">57.ts_react</a></li><li><a href="../html/58.react-ssr.html">58.react-ssr</a></li><li><a href="../html/59.react-ssr.html">59.react-ssr</a></li></ul></div>


<div class="warpper">

    <div class="page-toc">
        <ul><li><a href="#t01. webpack的插件机制">1. webpack的插件机制</a></li><li><a href="#t11. tapable">1. tapable</a></li><li><a href="#t22.tapable用法">2.tapable用法</a></li><li><a href="#t33. SyncHook">3. SyncHook</a></li><li><a href="#t44. SyncBailHook">4. SyncBailHook</a></li><li><a href="#t55. SyncWaterfallHook">5. SyncWaterfallHook</a></li><li><a href="#t66. SyncLoopHook">6. SyncLoopHook</a></li><li><a href="#t77. AsyncParallelHook">7. AsyncParallelHook</a><ul><li><a href="#t87.1 tap">7.1 tap</a></li><li><a href="#t97.2 tapAsync">7.2 tapAsync</a></li><li><a href="#t107.3 tapPromise">7.3 tapPromise</a></li></ul></li><li><a href="#t118. AsyncParallelBailHook">8. AsyncParallelBailHook</a><ul><li><a href="#t128.1 tap">8.1 tap</a></li><li><a href="#t138.2 tapAsync">8.2 tapAsync</a></li><li><a href="#t148.3 tapPromise">8.3 tapPromise</a></li></ul></li><li><a href="#t159. AsyncSeriesHook">9. AsyncSeriesHook</a><ul><li><a href="#t169.1 tap">9.1 tap</a></li><li><a href="#t179.2 tapAsync">9.2 tapAsync</a></li><li><a href="#t189.3 tapPromise">9.3 tapPromise</a></li></ul></li><li><a href="#t1910. AsyncSeriesBailHook">10. AsyncSeriesBailHook</a><ul><li><a href="#t2010.1 tap">10.1 tap</a></li><li><a href="#t2110.2 tabAsync">10.2 tabAsync</a></li><li><a href="#t2210.3 tapPromise">10.3 tapPromise</a></li></ul></li><li><a href="#t2311. AsyncSeriesWaterfallHook">11. AsyncSeriesWaterfallHook</a><ul><li><a href="#t2411.1 tap">11.1 tap</a></li><li><a href="#t2511.2 tapAsync">11.2 tapAsync</a></li><li><a href="#t2611.3 tapPromise">11.3 tapPromise</a></li></ul></li><li><a href="#t2712. tapable">12. tapable</a></li><li><a href="#t28参考">参考</a></li></ul>
    </div>
    
    <div class="content markdown-body">
        <h2 id="t01. webpack&#x7684;&#x63D2;&#x4EF6;&#x673A;&#x5236;">1. webpack&#x7684;&#x63D2;&#x4EF6;&#x673A;&#x5236; <a href="#t01. webpack&#x7684;&#x63D2;&#x4EF6;&#x673A;&#x5236;"> # </a></h2>
<p>&#x5728;&#x5177;&#x4F53;&#x4ECB;&#x7ECD;webpack&#x5185;&#x7F6E;&#x63D2;&#x4EF6;&#x4E0E;&#x94A9;&#x5B50;&#x53EF;&#x89C6;&#x5316;&#x5DE5;&#x5177;&#x4E4B;&#x524D;&#xFF0C;&#x6211;&#x4EEC;&#x5148;&#x6765;&#x4E86;&#x89E3;&#x4E00;&#x4E0B;webpack&#x4E2D;&#x7684;&#x63D2;&#x4EF6;&#x673A;&#x5236;&#x3002;
webpack&#x5B9E;&#x73B0;&#x63D2;&#x4EF6;&#x673A;&#x5236;&#x7684;&#x5927;&#x4F53;&#x65B9;&#x5F0F;&#x662F;&#xFF1A;</p>
<ul>
<li>&#x521B;&#x5EFA; - webpack&#x5728;&#x5176;&#x5185;&#x90E8;&#x5BF9;&#x8C61;&#x4E0A;&#x521B;&#x5EFA;&#x5404;&#x79CD;&#x94A9;&#x5B50;&#xFF1B;</li>
<li>&#x6CE8;&#x518C; - &#x63D2;&#x4EF6;&#x5C06;&#x81EA;&#x5DF1;&#x7684;&#x65B9;&#x6CD5;&#x6CE8;&#x518C;&#x5230;&#x5BF9;&#x5E94;&#x94A9;&#x5B50;&#x4E0A;&#xFF0C;&#x4EA4;&#x7ED9;webpack&#xFF1B;</li>
<li>&#x8C03;&#x7528; - webpack&#x7F16;&#x8BD1;&#x8FC7;&#x7A0B;&#x4E2D;&#xFF0C;&#x4F1A;&#x9002;&#x65F6;&#x5730;&#x89E6;&#x53D1;&#x76F8;&#x5E94;&#x94A9;&#x5B50;&#xFF0C;&#x56E0;&#x6B64;&#x4E5F;&#x5C31;&#x89E6;&#x53D1;&#x4E86;&#x63D2;&#x4EF6;&#x7684;&#x65B9;&#x6CD5;&#x3002;</li>
</ul>
<h2 id="t11. tapable">1. tapable <a href="#t11. tapable"> # </a></h2>
<p><code>Webpack</code>&#x672C;&#x8D28;&#x4E0A;&#x662F;&#x4E00;&#x79CD;&#x4E8B;&#x4EF6;&#x6D41;&#x7684;&#x673A;&#x5236;&#xFF0C;&#x5B83;&#x7684;&#x5DE5;&#x4F5C;&#x6D41;&#x7A0B;&#x5C31;&#x662F;&#x5C06;&#x5404;&#x4E2A;&#x63D2;&#x4EF6;&#x4E32;&#x8054;&#x8D77;&#x6765;&#xFF0C;&#x800C;&#x5B9E;&#x73B0;&#x8FD9;&#x4E00;&#x5207;&#x7684;&#x6838;&#x5FC3;&#x5C31;&#x662F;<code>Tapable</code>&#xFF0C;webpack&#x4E2D;&#x6700;&#x6838;&#x5FC3;&#x7684;&#x8D1F;&#x8D23;&#x7F16;&#x8BD1;&#x7684;<code>Compiler</code>&#x548C;&#x8D1F;&#x8D23;&#x521B;&#x5EFA;bundle&#x7684;<code>Compilation</code>&#x90FD;&#x662F;Tapable&#x7684;&#x5B9E;&#x4F8B;</p>
<h2 id="t22.tapable&#x7528;&#x6CD5;">2.tapable&#x7528;&#x6CD5; <a href="#t22.tapable&#x7528;&#x6CD5;"> # </a></h2>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> {
    SyncHook,
    SyncBailHook,
    SyncWaterfallHook,
    SyncLoopHook,
    AsyncParallelHook,
    AsyncParallelBailHook,
    AsyncSeriesHook,
    AsyncSeriesBailHook,
    AsyncSeriesWaterfallHook
 } = <span class="hljs-built_in">require</span>(<span class="hljs-string">&quot;tapable&quot;</span>);
</code></pre>
<p><img src="http://img.zhufengpeixun.cn/tapable.png" alt="tapable"></p>
<h2 id="t33. SyncHook">3. SyncHook <a href="#t33. SyncHook"> # </a></h2>
<p>&#x4E32;&#x884C;&#x540C;&#x6B65;&#x6267;&#x884C;,&#x4E0D;&#x5173;&#x5FC3;&#x8FD4;&#x56DE;&#x503C;</p>
<pre><code class="lang-js"><span class="hljs-comment">//let {SyncHook}=require(&apos;tapable&apos;);</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">SyncHook</span></span>{
    <span class="hljs-keyword">constructor</span>() {
        <span class="hljs-keyword">this</span>.tasks=[];
    }
    tap(name,task) {
        <span class="hljs-keyword">this</span>.tasks.push(task);
    }
    call() {
        <span class="hljs-keyword">this</span>.tasks.forEach(<span class="hljs-function"><span class="hljs-params">task</span>=&gt;</span>task(...arguments));
    }
}
<span class="hljs-keyword">let</span> queue = <span class="hljs-keyword">new</span> SyncHook([<span class="hljs-string">&apos;name&apos;</span>]);
queue.tap(<span class="hljs-string">&apos;1&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">name</span>)</span>{
  <span class="hljs-built_in">console</span>.log(name,<span class="hljs-number">1</span>);
});
queue.tap(<span class="hljs-string">&apos;2&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">name</span>)</span>{
  <span class="hljs-built_in">console</span>.log(name,<span class="hljs-number">2</span>);
});
queue.tap(<span class="hljs-string">&apos;3&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">name</span>)</span>{
  <span class="hljs-built_in">console</span>.log(name,<span class="hljs-number">3</span>);
});
queue.call(<span class="hljs-string">&apos;zfpx&apos;</span>);
</code></pre>
<h2 id="t44. SyncBailHook">4. SyncBailHook <a href="#t44. SyncBailHook"> # </a></h2>
<p>&#x4E32;&#x884C;&#x540C;&#x6B65;&#x6267;&#x884C;&#xFF0C;&#x6709;&#x4E00;&#x4E2A;&#x8FD4;&#x56DE;&#x503C;&#x4E0D;&#x4E3A;null&#x5219;&#x8DF3;&#x8FC7;&#x5269;&#x4E0B;&#x7684;&#x903B;&#x8F91;</p>
<pre><code class="lang-js"><span class="hljs-comment">//let {SyncBailHook}=require(&apos;tapable&apos;);</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">SyncBailHook</span></span>{
    <span class="hljs-keyword">constructor</span>() {
        <span class="hljs-keyword">this</span>.tasks=[];
    }
    tap(name,task) {
        <span class="hljs-keyword">this</span>.tasks.push(task);
    }
    call() {
        <span class="hljs-comment">// for (let i=0;i&lt;this.tasks.length;i++){</span>
        <span class="hljs-comment">//     let ret=this.tasks[i](...arguments);</span>
        <span class="hljs-comment">//     if (ret)</span>
        <span class="hljs-comment">//         break;</span>
        <span class="hljs-comment">// }</span>
        <span class="hljs-keyword">let</span> i=<span class="hljs-number">0</span>,ret;
        <span class="hljs-keyword">do</span> {
            ret=<span class="hljs-keyword">this</span>.tasks[i++](...arguments);
        } <span class="hljs-keyword">while</span> (!ret);
    }
}
<span class="hljs-keyword">let</span> queue = <span class="hljs-keyword">new</span> SyncBailHook([<span class="hljs-string">&apos;name&apos;</span>]);
queue.tap(<span class="hljs-string">&apos;1&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">name</span>)</span>{
  <span class="hljs-built_in">console</span>.log(name,<span class="hljs-number">1</span>);
  <span class="hljs-keyword">return</span> <span class="hljs-string">&apos;Wrong&apos;</span>;
});
queue.tap(<span class="hljs-string">&apos;2&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">name</span>)</span>{
  <span class="hljs-built_in">console</span>.log(name,<span class="hljs-number">2</span>);
});
queue.tap(<span class="hljs-string">&apos;3&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">name</span>)</span>{
  <span class="hljs-built_in">console</span>.log(name,<span class="hljs-number">3</span>);
});
queue.call(<span class="hljs-string">&apos;zfpx&apos;</span>);
</code></pre>
<h2 id="t55. SyncWaterfallHook">5. SyncWaterfallHook <a href="#t55. SyncWaterfallHook"> # </a></h2>
<pre><code class="lang-js"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">SyncWaterfallHook</span></span>{
    <span class="hljs-keyword">constructor</span>() {
        <span class="hljs-keyword">this</span>.tasks=[];
    }
    tap(name,task) {
        <span class="hljs-keyword">this</span>.tasks.push(task);
    }
    call() {
        <span class="hljs-keyword">let</span> [first,...tasks]=<span class="hljs-keyword">this</span>.tasks;
        tasks.reduce(<span class="hljs-function">(<span class="hljs-params">ret,task</span>)=&gt;</span>task(ret),first(...arguments));

        <span class="hljs-comment">//this.tasks.reduce((a,b) =&gt; (...args) =&gt; b(a(...args)))(...arguments);</span>
    }
}
<span class="hljs-keyword">let</span> queue = <span class="hljs-keyword">new</span> SyncWaterfallHook([<span class="hljs-string">&apos;name&apos;</span>]);
queue.tap(<span class="hljs-string">&apos;1&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">name,age</span>)</span>{
  <span class="hljs-built_in">console</span>.log(name,age,<span class="hljs-number">1</span>);
  <span class="hljs-keyword">return</span> <span class="hljs-number">1</span>;
});
queue.tap(<span class="hljs-string">&apos;2&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">data</span>)</span>{
    <span class="hljs-built_in">console</span>.log(data,<span class="hljs-number">2</span>);
    <span class="hljs-keyword">return</span> <span class="hljs-number">2</span>;
});
queue.tap(<span class="hljs-string">&apos;3&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">data</span>)</span>{
  <span class="hljs-built_in">console</span>.log(data,<span class="hljs-number">3</span>);
});
queue.call(<span class="hljs-string">&apos;zfpx&apos;</span>,<span class="hljs-number">9</span>);

</code></pre>
<h2 id="t66. SyncLoopHook">6. SyncLoopHook <a href="#t66. SyncLoopHook"> # </a></h2>
<p>&#x76D1;&#x542C;&#x51FD;&#x6570;&#x8FD4;&#x56DE;true&#x8868;&#x793A;&#x7EE7;&#x7EED;&#x5FAA;&#x73AF;&#xFF0C;&#x8FD4;&#x56DE;undefine&#x8868;&#x793A;&#x7ED3;&#x675F;&#x5FAA;&#x73AF;</p>
<pre><code class="lang-js"><span class="hljs-comment">//let {SyncHook}=require(&apos;tapable&apos;);</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">SyncLoopHook</span></span>{
    <span class="hljs-keyword">constructor</span>() {
        <span class="hljs-keyword">this</span>.tasks=[];
    }
    tap(name,task) {
        <span class="hljs-keyword">this</span>.tasks.push(task);
    }
    call(...args) {    
        <span class="hljs-keyword">this</span>.tasks.forEach(<span class="hljs-function"><span class="hljs-params">task</span> =&gt;</span> {
            <span class="hljs-keyword">let</span> ret=<span class="hljs-literal">true</span>;
            <span class="hljs-keyword">do</span> {
                ret = task(...args);
            }<span class="hljs-keyword">while</span>(ret == <span class="hljs-literal">true</span> || !(ret === <span class="hljs-literal">undefined</span>))
        });
    }
}
<span class="hljs-keyword">let</span> queue = <span class="hljs-keyword">new</span> SyncLoopHook([<span class="hljs-string">&apos;name&apos;</span>]);
<span class="hljs-keyword">let</span> count = <span class="hljs-number">0</span>;
queue.tap(<span class="hljs-string">&apos;1&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">name</span>)</span>{
    <span class="hljs-built_in">console</span>.log(count++);
    <span class="hljs-keyword">if</span>(count==<span class="hljs-number">3</span>){
        <span class="hljs-keyword">return</span>;
    }<span class="hljs-keyword">else</span>{
        <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
    }
});
queue.call(<span class="hljs-string">&apos;zfpx&apos;</span>);
</code></pre>
<h2 id="t77. AsyncParallelHook">7. AsyncParallelHook <a href="#t77. AsyncParallelHook"> # </a></h2>
<p>&#x5F02;&#x6B65;&#x5E76;&#x884C;&#x6267;&#x884C;&#x94A9;&#x5B50;</p>
<h3 id="t87.1 tap">7.1 tap <a href="#t87.1 tap"> # </a></h3>
<pre><code class="lang-js"><span class="hljs-comment">//let {AsyncParallelHook}=require(&apos;tapable&apos;);</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">AsyncParallelHook</span></span>{
    <span class="hljs-keyword">constructor</span>() {
        <span class="hljs-keyword">this</span>.tasks=[];
    }
    tap(name,task) {
        <span class="hljs-keyword">this</span>.tasks.push(task);
    }
    callAsync() {
        <span class="hljs-keyword">let</span> args=<span class="hljs-built_in">Array</span>.from(<span class="hljs-built_in">arguments</span>);
        <span class="hljs-keyword">let</span> callback=args.pop();
        <span class="hljs-keyword">this</span>.tasks.forEach(<span class="hljs-function"><span class="hljs-params">task</span> =&gt;</span> task(...args));
        callback();
    }
}
<span class="hljs-keyword">let</span> queue = <span class="hljs-keyword">new</span> AsyncParallelHook([<span class="hljs-string">&apos;name&apos;</span>]);
<span class="hljs-built_in">console</span>.time(<span class="hljs-string">&apos;cost&apos;</span>);
queue.tap(<span class="hljs-string">&apos;1&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">name</span>)</span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-number">1</span>);
});
queue.tap(<span class="hljs-string">&apos;2&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">name</span>)</span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-number">2</span>);
});
queue.tap(<span class="hljs-string">&apos;3&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">name</span>)</span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-number">3</span>);
});
queue.callAsync(<span class="hljs-string">&apos;zfpx&apos;</span>,err=&gt;{
    <span class="hljs-built_in">console</span>.log(err);
    <span class="hljs-built_in">console</span>.timeEnd(<span class="hljs-string">&apos;cost&apos;</span>);
});
</code></pre>
<h3 id="t97.2 tapAsync">7.2 tapAsync <a href="#t97.2 tapAsync"> # </a></h3>
<pre><code class="lang-js"><span class="hljs-comment">//let {AsyncParallelHook}=require(&apos;tapable&apos;);</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">AsyncParallelHook</span></span>{
    <span class="hljs-keyword">constructor</span>() {
        <span class="hljs-keyword">this</span>.tasks=[];
    }
    tapAsync(name,task) {
        <span class="hljs-keyword">this</span>.tasks.push(task);
    }
    callAsync() {
        <span class="hljs-keyword">let</span> args=<span class="hljs-built_in">Array</span>.from(<span class="hljs-built_in">arguments</span>);
        <span class="hljs-keyword">let</span> callback=args.pop();
        <span class="hljs-keyword">let</span> i=<span class="hljs-number">0</span>,length = <span class="hljs-keyword">this</span>.tasks.length;
        <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">done</span>(<span class="hljs-params">err</span>) </span>{
            <span class="hljs-keyword">if</span> (++i == length) {
                callback(err);
            }
        }
        <span class="hljs-keyword">this</span>.tasks.forEach(<span class="hljs-function"><span class="hljs-params">task</span> =&gt;</span> {
            task(...args,done);
        });
    }
}
<span class="hljs-keyword">let</span> queue = <span class="hljs-keyword">new</span> AsyncParallelHook([<span class="hljs-string">&apos;name&apos;</span>]);
<span class="hljs-built_in">console</span>.time(<span class="hljs-string">&apos;cost&apos;</span>);
queue.tapAsync(<span class="hljs-string">&apos;1&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">name,callback</span>)</span>{
    setTimeout(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
        <span class="hljs-built_in">console</span>.log(<span class="hljs-number">1</span>);
        callback();
    },<span class="hljs-number">1000</span>)
});
queue.tapAsync(<span class="hljs-string">&apos;2&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">name,callback</span>)</span>{
    setTimeout(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
        <span class="hljs-built_in">console</span>.log(<span class="hljs-number">2</span>);
        callback();
    },<span class="hljs-number">2000</span>)
});
queue.tapAsync(<span class="hljs-string">&apos;3&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">name,callback</span>)</span>{
    setTimeout(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
        <span class="hljs-built_in">console</span>.log(<span class="hljs-number">3</span>);
        callback();
    },<span class="hljs-number">3000</span>)
});
queue.callAsync(<span class="hljs-string">&apos;zfpx&apos;</span>,err=&gt;{
    <span class="hljs-built_in">console</span>.log(err);
    <span class="hljs-built_in">console</span>.timeEnd(<span class="hljs-string">&apos;cost&apos;</span>);
});
</code></pre>
<h3 id="t107.3 tapPromise">7.3 tapPromise <a href="#t107.3 tapPromise"> # </a></h3>
<pre><code class="lang-js"><span class="hljs-comment">//let {AsyncParallelHook}=require(&apos;tapable&apos;);</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">AsyncParallelHook</span></span>{
    <span class="hljs-keyword">constructor</span>() {
        <span class="hljs-keyword">this</span>.tasks=[];
    }
    tapPromise(name,task) {
        <span class="hljs-keyword">this</span>.tasks.push(task);
    }
    promise() {
        <span class="hljs-keyword">let</span> promises = <span class="hljs-keyword">this</span>.tasks.map(<span class="hljs-function"><span class="hljs-params">task</span> =&gt;</span> task());
        <span class="hljs-keyword">return</span> <span class="hljs-built_in">Promise</span>.all(promises);
    }
}
<span class="hljs-keyword">let</span> queue = <span class="hljs-keyword">new</span> AsyncParallelHook([<span class="hljs-string">&apos;name&apos;</span>]);
<span class="hljs-built_in">console</span>.time(<span class="hljs-string">&apos;cost&apos;</span>);
queue.tapPromise(<span class="hljs-string">&apos;1&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">name</span>)</span>{
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">resolve,reject</span>)</span>{
        setTimeout(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
            <span class="hljs-built_in">console</span>.log(<span class="hljs-number">1</span>);
            resolve();
        },<span class="hljs-number">1000</span>)
    });

});
queue.tapPromise(<span class="hljs-string">&apos;2&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">name</span>)</span>{
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">resolve,reject</span>)</span>{
        setTimeout(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
            <span class="hljs-built_in">console</span>.log(<span class="hljs-number">2</span>);
            resolve();
        },<span class="hljs-number">2000</span>)
    });
});
queue.tapPromise(<span class="hljs-string">&apos;3&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">name</span>)</span>{
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">resolve,reject</span>)</span>{
        setTimeout(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
            <span class="hljs-built_in">console</span>.log(<span class="hljs-number">3</span>);
            resolve();
        },<span class="hljs-number">3000</span>)
    });
});
queue.promise(<span class="hljs-string">&apos;zfpx&apos;</span>).then(<span class="hljs-function"><span class="hljs-params">()</span>=&gt;</span>{
    <span class="hljs-built_in">console</span>.timeEnd(<span class="hljs-string">&apos;cost&apos;</span>);
})
</code></pre>
<h2 id="t118. AsyncParallelBailHook">8. AsyncParallelBailHook <a href="#t118. AsyncParallelBailHook"> # </a></h2>
<p>&#x5E26;&#x4FDD;&#x9669;&#x7684;&#x5F02;&#x6B65;&#x5E76;&#x884C;&#x6267;&#x884C;&#x94A9;&#x5B50;</p>
<h3 id="t128.1 tap">8.1 tap <a href="#t128.1 tap"> # </a></h3>
<pre><code class="lang-js"><span class="hljs-comment">//let {AsyncParallelBailHook} = require(&apos;tapable&apos;);</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">AsyncParallelBailHook</span></span>{
    <span class="hljs-keyword">constructor</span>() {
        <span class="hljs-keyword">this</span>.tasks=[];
    }
    tap(name,task) {
        <span class="hljs-keyword">this</span>.tasks.push(task);
    }
    callAsync() {
        <span class="hljs-keyword">let</span> args=<span class="hljs-built_in">Array</span>.from(<span class="hljs-built_in">arguments</span>);
        <span class="hljs-keyword">let</span> callback=args.pop();
        <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i=<span class="hljs-number">0</span>;i&lt;<span class="hljs-keyword">this</span>.tasks.length;i++){
            <span class="hljs-keyword">let</span> ret=<span class="hljs-keyword">this</span>.tasks[i](...args);
            <span class="hljs-keyword">if</span> (ret) {
                <span class="hljs-keyword">return</span> callback(ret);
            }
        }
    }
}
<span class="hljs-keyword">let</span> queue=<span class="hljs-keyword">new</span> AsyncParallelBailHook([<span class="hljs-string">&apos;name&apos;</span>]);
<span class="hljs-built_in">console</span>.time(<span class="hljs-string">&apos;cost&apos;</span>);
queue.tap(<span class="hljs-string">&apos;1&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">name</span>)</span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-number">1</span>);
    <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;Wrong&quot;</span>;
});
queue.tap(<span class="hljs-string">&apos;2&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">name</span>)</span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-number">2</span>);
});
queue.tap(<span class="hljs-string">&apos;3&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">name</span>)</span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-number">3</span>);
});
queue.callAsync(<span class="hljs-string">&apos;zfpx&apos;</span>,err=&gt;{
    <span class="hljs-built_in">console</span>.log(err);
    <span class="hljs-built_in">console</span>.timeEnd(<span class="hljs-string">&apos;cost&apos;</span>);
});
</code></pre>
<h3 id="t138.2 tapAsync">8.2 tapAsync <a href="#t138.2 tapAsync"> # </a></h3>
<pre><code class="lang-js"><span class="hljs-comment">//let {AsyncParallelBailHook} = require(&apos;tapable&apos;);</span>

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">AsyncParallelBailHook</span></span>{
    <span class="hljs-keyword">constructor</span>() {
        <span class="hljs-keyword">this</span>.tasks=[];
    }
    tapAsync(name,task) {
        <span class="hljs-keyword">this</span>.tasks.push(task);
    }
    callAsync() {
        <span class="hljs-keyword">let</span> args=<span class="hljs-built_in">Array</span>.from(<span class="hljs-built_in">arguments</span>);
        <span class="hljs-keyword">let</span> finalCallback=args.pop();
        <span class="hljs-keyword">let</span> count=<span class="hljs-number">0</span>,total=<span class="hljs-keyword">this</span>.tasks.length;
        <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">done</span>(<span class="hljs-params">err</span>) </span>{
            <span class="hljs-keyword">if</span> (err) {
                <span class="hljs-keyword">return</span> finalCallback(err);
            } <span class="hljs-keyword">else</span> {
                <span class="hljs-keyword">if</span> (++count == total) {
                    <span class="hljs-keyword">return</span> finalCallback();
                }
            }
        }
        <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i=<span class="hljs-number">0</span>;i&lt;total;i++){
            <span class="hljs-keyword">let</span> task=<span class="hljs-keyword">this</span>.tasks[i];
            task(...args,done);
        }
    }
}
<span class="hljs-keyword">let</span> queue=<span class="hljs-keyword">new</span> AsyncParallelBailHook([<span class="hljs-string">&apos;name&apos;</span>]);
<span class="hljs-built_in">console</span>.time(<span class="hljs-string">&apos;cost&apos;</span>);
queue.tapAsync(<span class="hljs-string">&apos;1&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">name,callback</span>)</span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-number">1</span>);
    callback(<span class="hljs-string">&apos;Wrong&apos;</span>);
});
queue.tapAsync(<span class="hljs-string">&apos;2&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">name,callback</span>)</span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-number">2</span>);
    callback();
});
queue.tapAsync(<span class="hljs-string">&apos;3&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">name,callback</span>)</span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-number">3</span>);
    callback();
});
queue.callAsync(<span class="hljs-string">&apos;zfpx&apos;</span>,err=&gt;{
    <span class="hljs-built_in">console</span>.log(err);
    <span class="hljs-built_in">console</span>.timeEnd(<span class="hljs-string">&apos;cost&apos;</span>);
});
</code></pre>
<h3 id="t148.3 tapPromise">8.3 tapPromise <a href="#t148.3 tapPromise"> # </a></h3>
<pre><code class="lang-js"><span class="hljs-comment">//let {AsyncParallelBailHook} = require(&apos;tapable&apos;);</span>

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">AsyncParallelBailHook</span></span>{
    <span class="hljs-keyword">constructor</span>() {
        <span class="hljs-keyword">this</span>.tasks=[];
    }
    tapPromise(name,task) {
        <span class="hljs-keyword">this</span>.tasks.push(task);
    }
    promise() {
        <span class="hljs-keyword">let</span> args=<span class="hljs-built_in">Array</span>.from(<span class="hljs-built_in">arguments</span>);
        <span class="hljs-keyword">let</span> promises = <span class="hljs-keyword">this</span>.tasks.map(<span class="hljs-function"><span class="hljs-params">task</span> =&gt;</span> task(...arguments));
        <span class="hljs-keyword">return</span> <span class="hljs-built_in">Promise</span>.all(promises);
    }
}
<span class="hljs-keyword">let</span> queue = <span class="hljs-keyword">new</span> AsyncParallelBailHook([<span class="hljs-string">&apos;name&apos;</span>]);
<span class="hljs-built_in">console</span>.time(<span class="hljs-string">&apos;cost&apos;</span>);
queue.tapPromise(<span class="hljs-string">&apos;1&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">name</span>)</span>{
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">resolve,reject</span>)</span>{
        setTimeout(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
            <span class="hljs-built_in">console</span>.log(<span class="hljs-number">1</span>);
            resolve();
        },<span class="hljs-number">1000</span>)
    });
});
queue.tapPromise(<span class="hljs-string">&apos;2&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">name</span>)</span>{
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">resolve,reject</span>)</span>{
        setTimeout(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
            <span class="hljs-built_in">console</span>.log(<span class="hljs-number">2</span>);
            reject();
        },<span class="hljs-number">2000</span>)
    });
});

queue.tapPromise(<span class="hljs-string">&apos;3&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">name</span>)</span>{
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">resolve,reject</span>)</span>{
        setTimeout(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
            <span class="hljs-built_in">console</span>.log(<span class="hljs-number">3</span>);
            resolve();
        },<span class="hljs-number">3000</span>)
    });
});

queue.promise(<span class="hljs-string">&apos;zfpx&apos;</span>).then(<span class="hljs-function"><span class="hljs-params">()</span>=&gt;</span>{
    <span class="hljs-built_in">console</span>.timeEnd(<span class="hljs-string">&apos;cost&apos;</span>);
},err =&gt; {
    <span class="hljs-built_in">console</span>.error(err);
    <span class="hljs-built_in">console</span>.timeEnd(<span class="hljs-string">&apos;cost&apos;</span>);
})
</code></pre>
<h2 id="t159. AsyncSeriesHook">9. AsyncSeriesHook <a href="#t159. AsyncSeriesHook"> # </a></h2>
<p>&#x5F02;&#x6B65;&#x4E32;&#x884C;&#x94A9;&#x5B50;</p>
<h3 id="t169.1 tap">9.1 tap <a href="#t169.1 tap"> # </a></h3>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> {AsyncSeriesHook} = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;tapable&apos;</span>);
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">AsyncSeriesHook</span></span>{
    <span class="hljs-keyword">constructor</span>() {
        <span class="hljs-keyword">this</span>.tasks=[];
    }
    tap(name,task) {
        <span class="hljs-keyword">this</span>.tasks.push(task);
    }
    callAsync() {
        <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i=<span class="hljs-number">0</span>;i&lt;total;i++){
            <span class="hljs-keyword">let</span> task=<span class="hljs-keyword">this</span>.tasks[i];
            task(...args,done);
        }
    }
}
<span class="hljs-keyword">let</span> queue = <span class="hljs-keyword">new</span> AsyncSeriesHook([<span class="hljs-string">&apos;name&apos;</span>]);
<span class="hljs-built_in">console</span>.time(<span class="hljs-string">&apos;cost&apos;</span>);
queue.tap(<span class="hljs-string">&apos;1&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">name</span>)</span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-number">1</span>);
});
queue.tap(<span class="hljs-string">&apos;2&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">name</span>)</span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-number">2</span>);
});
queue.tap(<span class="hljs-string">&apos;3&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">name</span>)</span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-number">3</span>);
});
queue.callAsync(<span class="hljs-string">&apos;zfpx&apos;</span>,err=&gt;{
    <span class="hljs-built_in">console</span>.log(err);
    <span class="hljs-built_in">console</span>.timeEnd(<span class="hljs-string">&apos;cost&apos;</span>);
});
</code></pre>
<h3 id="t179.2 tapAsync">9.2 tapAsync <a href="#t179.2 tapAsync"> # </a></h3>
<pre><code class="lang-js"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">AsyncSeriesBailHook</span></span>{
    <span class="hljs-keyword">constructor</span>() {
        <span class="hljs-keyword">this</span>.tasks=[];
    }
    tapAsync(name,task) {
        <span class="hljs-keyword">this</span>.tasks.push(task);
    }
    callAsync() {
        <span class="hljs-keyword">let</span> args = <span class="hljs-built_in">Array</span>.from(<span class="hljs-built_in">arguments</span>);
        <span class="hljs-keyword">let</span> finalCallback = args.pop();
        <span class="hljs-keyword">let</span> index = <span class="hljs-number">0</span>, length = <span class="hljs-keyword">this</span>.tasks.length;
        <span class="hljs-keyword">let</span> next = <span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> {
            <span class="hljs-keyword">let</span> task = <span class="hljs-keyword">this</span>.tasks[index++];
            <span class="hljs-keyword">if</span> (task) {
                task(...args, next);
            } <span class="hljs-keyword">else</span> {
                finalCallback();
            }
        }
        next();
    }
}
<span class="hljs-keyword">let</span> queue = <span class="hljs-keyword">new</span> AsyncSeriesHook([<span class="hljs-string">&apos;name&apos;</span>]);
<span class="hljs-built_in">console</span>.time(<span class="hljs-string">&apos;cost&apos;</span>);
queue.tapAsync(<span class="hljs-string">&apos;1&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">name,callback</span>)</span>{
   setTimeout(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
       <span class="hljs-built_in">console</span>.log(<span class="hljs-number">1</span>);
   },<span class="hljs-number">1000</span>)
});
queue.tapAsync(<span class="hljs-string">&apos;2&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">name,callback</span>)</span>{
    setTimeout(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
        <span class="hljs-built_in">console</span>.log(<span class="hljs-number">2</span>);
        callback();
    },<span class="hljs-number">2000</span>)
});
queue.tapAsync(<span class="hljs-string">&apos;3&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">name,callback</span>)</span>{
    setTimeout(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
        <span class="hljs-built_in">console</span>.log(<span class="hljs-number">3</span>);
        callback();
    },<span class="hljs-number">3000</span>)
});
queue.callAsync(<span class="hljs-string">&apos;zfpx&apos;</span>,err=&gt;{
    <span class="hljs-built_in">console</span>.log(err);
    <span class="hljs-built_in">console</span>.timeEnd(<span class="hljs-string">&apos;cost&apos;</span>);
});
</code></pre>
<h3 id="t189.3 tapPromise">9.3 tapPromise <a href="#t189.3 tapPromise"> # </a></h3>
<pre><code class="lang-js"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">AsyncSeriesHook</span></span>{
    <span class="hljs-keyword">constructor</span>() {
        <span class="hljs-keyword">this</span>.tasks=[];
    }
    tapPromise(name,task) {
        <span class="hljs-keyword">this</span>.tasks.push(task);
    }
    promise() {
         <span class="hljs-comment">//first&#x662F;&#x7B2C;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#xFF0C; tasks&#x662F;&#x5269;&#x4E0B;&#x7684;&#x51FD;&#x6570;</span>
        <span class="hljs-keyword">let</span> [first, ...tasks] = <span class="hljs-keyword">this</span>.tasks;
        <span class="hljs-keyword">return</span> tasks.reduce(<span class="hljs-function">(<span class="hljs-params">a, b</span>) =&gt;</span> {
            <span class="hljs-keyword">return</span> a.then(<span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> b());
        }, first(...args));
    }
}
<span class="hljs-keyword">let</span> queue=<span class="hljs-keyword">new</span> AsyncSeriesHook([<span class="hljs-string">&apos;name&apos;</span>]);
<span class="hljs-built_in">console</span>.time(<span class="hljs-string">&apos;cost&apos;</span>);
queue.tapPromise(<span class="hljs-string">&apos;1&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">name</span>)</span>{
   <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">resolve</span>)</span>{
       setTimeout(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
           <span class="hljs-built_in">console</span>.log(<span class="hljs-number">1</span>);
           resolve();
       },<span class="hljs-number">1000</span>)
   });
});
queue.tapPromise(<span class="hljs-string">&apos;2&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">name,callback</span>)</span>{
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">resolve</span>)</span>{
        setTimeout(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
            <span class="hljs-built_in">console</span>.log(<span class="hljs-number">2</span>);
            resolve();
        },<span class="hljs-number">2000</span>)
    });
});
queue.tapPromise(<span class="hljs-string">&apos;3&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">name,callback</span>)</span>{
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">resolve</span>)</span>{
        setTimeout(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
            <span class="hljs-built_in">console</span>.log(<span class="hljs-number">3</span>);
            resolve();
        },<span class="hljs-number">3000</span>)
    });
});
queue.promise(<span class="hljs-string">&apos;zfpx&apos;</span>).then(<span class="hljs-function"><span class="hljs-params">data</span>=&gt;</span>{
    <span class="hljs-built_in">console</span>.log(data);
    <span class="hljs-built_in">console</span>.timeEnd(<span class="hljs-string">&apos;cost&apos;</span>);
});
</code></pre>
<h2 id="t1910. AsyncSeriesBailHook">10. AsyncSeriesBailHook <a href="#t1910. AsyncSeriesBailHook"> # </a></h2>
<h3 id="t2010.1 tap">10.1 tap <a href="#t2010.1 tap"> # </a></h3>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> {AsyncSeriesBailHook} = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;tapable&apos;</span>);
<span class="hljs-keyword">let</span> queue = <span class="hljs-keyword">new</span> AsyncSeriesBailHook([<span class="hljs-string">&apos;name&apos;</span>]);
<span class="hljs-built_in">console</span>.time(<span class="hljs-string">&apos;cost&apos;</span>);
queue.tap(<span class="hljs-string">&apos;1&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">name</span>)</span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-number">1</span>);
    <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;Wrong&quot;</span>;
});
queue.tap(<span class="hljs-string">&apos;2&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">name</span>)</span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-number">2</span>);
});
queue.tap(<span class="hljs-string">&apos;3&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">name</span>)</span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-number">3</span>);
});
queue.callAsync(<span class="hljs-string">&apos;zfpx&apos;</span>,err=&gt;{
    <span class="hljs-built_in">console</span>.log(err);
    <span class="hljs-built_in">console</span>.timeEnd(<span class="hljs-string">&apos;cost&apos;</span>);
});
</code></pre>
<h3 id="t2110.2 tabAsync">10.2 tabAsync <a href="#t2110.2 tabAsync"> # </a></h3>
<pre><code class="lang-js"><span class="hljs-comment">//let {AsyncSeriesBailHook}=require(&apos;tapable&apos;);</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">AsyncSeriesBailHook</span></span>{
    <span class="hljs-keyword">constructor</span>() {
        <span class="hljs-keyword">this</span>.tasks=[];
    }
    tapAsync(name,task) {
        <span class="hljs-keyword">this</span>.tasks.push(task);
    }
    callAsync() {
        <span class="hljs-keyword">let</span> args=<span class="hljs-built_in">Array</span>.from(<span class="hljs-built_in">arguments</span>);
        <span class="hljs-keyword">let</span> callback=args.pop();
        <span class="hljs-keyword">let</span> i=<span class="hljs-number">0</span>,size = <span class="hljs-keyword">this</span>.tasks.length;
        <span class="hljs-keyword">let</span> next=<span class="hljs-function">(<span class="hljs-params">err</span>) =&gt;</span> {
            <span class="hljs-keyword">if</span> (err) <span class="hljs-keyword">return</span>  callback(err);
            <span class="hljs-keyword">let</span> task=<span class="hljs-keyword">this</span>.tasks[i++];
            task?task(...args,next):callback();
        }
        next();
    }
}
<span class="hljs-keyword">let</span> queue = <span class="hljs-keyword">new</span> AsyncSeriesBailHook([<span class="hljs-string">&apos;name&apos;</span>]);
<span class="hljs-built_in">console</span>.time(<span class="hljs-string">&apos;cost&apos;</span>);
queue.tapAsync(<span class="hljs-string">&apos;1&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">name,callback</span>)</span>{
   setTimeout(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
       <span class="hljs-built_in">console</span>.log(<span class="hljs-number">1</span>);
       callback(<span class="hljs-string">&apos;wrong&apos;</span>);
   },<span class="hljs-number">1000</span>)
});
queue.tapAsync(<span class="hljs-string">&apos;2&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">name,callback</span>)</span>{
    setTimeout(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
        <span class="hljs-built_in">console</span>.log(<span class="hljs-number">2</span>);
        callback();
    },<span class="hljs-number">2000</span>)
});
queue.tapAsync(<span class="hljs-string">&apos;3&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">name,callback</span>)</span>{
    setTimeout(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
        <span class="hljs-built_in">console</span>.log(<span class="hljs-number">3</span>);
        callback();
    },<span class="hljs-number">3000</span>)
});
queue.callAsync(<span class="hljs-string">&apos;zfpx&apos;</span>,err=&gt;{
    <span class="hljs-built_in">console</span>.log(err);
    <span class="hljs-built_in">console</span>.timeEnd(<span class="hljs-string">&apos;cost&apos;</span>);
});
</code></pre>
<h3 id="t2210.3 tapPromise">10.3 tapPromise <a href="#t2210.3 tapPromise"> # </a></h3>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> {AsyncSeriesBailHook} = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;tapable&apos;</span>);
<span class="hljs-keyword">let</span> queue = <span class="hljs-keyword">new</span> AsyncSeriesBailHook([<span class="hljs-string">&apos;name&apos;</span>]);
<span class="hljs-built_in">console</span>.time(<span class="hljs-string">&apos;cost&apos;</span>);
queue.tapPromise(<span class="hljs-string">&apos;1&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">name</span>)</span>{
   <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">resolve,reject</span>)</span>{
       setTimeout(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
           <span class="hljs-built_in">console</span>.log(<span class="hljs-number">1</span>);
           <span class="hljs-comment">//resolve();</span>
           reject();
       },<span class="hljs-number">1000</span>)
   });
});
queue.tapPromise(<span class="hljs-string">&apos;2&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">name,callback</span>)</span>{
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">resolve</span>)</span>{
        setTimeout(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
            <span class="hljs-built_in">console</span>.log(<span class="hljs-number">2</span>);
            resolve();
        },<span class="hljs-number">2000</span>)
    });
});
queue.tapPromise(<span class="hljs-string">&apos;3&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">name,callback</span>)</span>{
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">resolve</span>)</span>{
        setTimeout(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
            <span class="hljs-built_in">console</span>.log(<span class="hljs-number">3</span>);
            resolve();
        },<span class="hljs-number">3000</span>)
    });
});
queue.promise(<span class="hljs-string">&apos;zfpx&apos;</span>).then(<span class="hljs-function"><span class="hljs-params">err</span>=&gt;</span>{
    <span class="hljs-built_in">console</span>.log(err);
    <span class="hljs-built_in">console</span>.timeEnd(<span class="hljs-string">&apos;cost&apos;</span>);
},err=&gt;{
    <span class="hljs-built_in">console</span>.log(err);
    <span class="hljs-built_in">console</span>.timeEnd(<span class="hljs-string">&apos;cost&apos;</span>);
});
</code></pre>
<h2 id="t2311. AsyncSeriesWaterfallHook">11. AsyncSeriesWaterfallHook <a href="#t2311. AsyncSeriesWaterfallHook"> # </a></h2>
<h3 id="t2411.1 tap">11.1 tap <a href="#t2411.1 tap"> # </a></h3>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> {AsyncSeriesWaterfallHook} = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;tapable&apos;</span>);
<span class="hljs-keyword">let</span> queue = <span class="hljs-keyword">new</span> AsyncSeriesWaterfallHook([<span class="hljs-string">&apos;name&apos;</span>]);
<span class="hljs-built_in">console</span>.time(<span class="hljs-string">&apos;cost&apos;</span>);
queue.tap(<span class="hljs-string">&apos;1&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">name,callback</span>)</span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-number">1</span>);
});
queue.tap(<span class="hljs-string">&apos;2&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">data</span>)</span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-number">2</span>,data);
});
queue.tap(<span class="hljs-string">&apos;3&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">data</span>)</span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-number">3</span>,data);
});
queue.callAsync(<span class="hljs-string">&apos;zfpx&apos;</span>,err=&gt;{
    <span class="hljs-built_in">console</span>.log(err);
    <span class="hljs-built_in">console</span>.timeEnd(<span class="hljs-string">&apos;cost&apos;</span>);
});
</code></pre>
<h3 id="t2511.2 tapAsync">11.2 tapAsync <a href="#t2511.2 tapAsync"> # </a></h3>
<pre><code class="lang-js"><span class="hljs-comment">//let {AsyncSeriesBailHook}=require(&apos;tapable&apos;);</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">AsyncSeriesWaterfallHook</span></span>{
    <span class="hljs-keyword">constructor</span>() {
        <span class="hljs-keyword">this</span>.tasks=[];
    }
    tapAsync(name,task) {
        <span class="hljs-keyword">this</span>.tasks.push(task);
    }
    callAsync() {
        <span class="hljs-keyword">let</span> args=<span class="hljs-built_in">Array</span>.from(<span class="hljs-built_in">arguments</span>);
        <span class="hljs-keyword">let</span> callback=args.pop();
        <span class="hljs-keyword">let</span> i=<span class="hljs-number">0</span>,size = <span class="hljs-keyword">this</span>.tasks.length;
        <span class="hljs-keyword">let</span> next=<span class="hljs-function">(<span class="hljs-params">err,data</span>) =&gt;</span> {
            <span class="hljs-keyword">if</span> (err) <span class="hljs-keyword">return</span>  callback(err);
            <span class="hljs-keyword">let</span> task=<span class="hljs-keyword">this</span>.tasks[i++];
            <span class="hljs-keyword">if</span> (task) {
                <span class="hljs-keyword">if</span> (i==<span class="hljs-number">0</span>) {
                    task(...args,next);
                } <span class="hljs-keyword">else</span> {
                    task(data,next);
                }

            } <span class="hljs-keyword">else</span> {
                callback(err,data);
            }
        }
        next();
    }
}
<span class="hljs-keyword">let</span> queue = <span class="hljs-keyword">new</span> AsyncSeriesWaterfallHook([<span class="hljs-string">&apos;name&apos;</span>]);
<span class="hljs-built_in">console</span>.time(<span class="hljs-string">&apos;cost&apos;</span>);
queue.tapAsync(<span class="hljs-string">&apos;1&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">name,callback</span>)</span>{
   setTimeout(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
       <span class="hljs-built_in">console</span>.log(<span class="hljs-number">1</span>);
       callback(<span class="hljs-literal">null</span>,<span class="hljs-number">1</span>);
   },<span class="hljs-number">1000</span>)
});
queue.tapAsync(<span class="hljs-string">&apos;2&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">data,callback</span>)</span>{
    setTimeout(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
        <span class="hljs-built_in">console</span>.log(<span class="hljs-number">2</span>);
        callback(<span class="hljs-literal">null</span>,<span class="hljs-number">2</span>);
    },<span class="hljs-number">2000</span>)
});
queue.tapAsync(<span class="hljs-string">&apos;3&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">data,callback</span>)</span>{
    setTimeout(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
        <span class="hljs-built_in">console</span>.log(<span class="hljs-number">3</span>);
        callback(<span class="hljs-literal">null</span>,<span class="hljs-number">3</span>);
    },<span class="hljs-number">3000</span>)
});
queue.callAsync(<span class="hljs-string">&apos;zfpx&apos;</span>,(err,data)=&gt;{
    <span class="hljs-built_in">console</span>.log(err,data);
    <span class="hljs-built_in">console</span>.timeEnd(<span class="hljs-string">&apos;cost&apos;</span>);
});
</code></pre>
<h3 id="t2611.3 tapPromise">11.3 tapPromise <a href="#t2611.3 tapPromise"> # </a></h3>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> {AsyncSeriesWaterfallHook} = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;tapable&apos;</span>);
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">AsyncSeriesWaterfallHook</span> </span>{
    <span class="hljs-keyword">constructor</span>() {
        <span class="hljs-keyword">this</span>.tasks = [];
    }
    tapPromise(name, task) {
        <span class="hljs-keyword">this</span>.tasks.push(task);
    }
    promise(...args) {
        <span class="hljs-comment">//first&#x662F;&#x7B2C;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#xFF0C; tasks&#x662F;&#x5269;&#x4E0B;&#x7684;&#x51FD;&#x6570;</span>
        <span class="hljs-keyword">let</span> [first, ...tasks] = <span class="hljs-keyword">this</span>.tasks;
        <span class="hljs-keyword">return</span> tasks.reduce(<span class="hljs-function">(<span class="hljs-params">a, b</span>) =&gt;</span> {
            <span class="hljs-keyword">return</span> a.then(<span class="hljs-function">(<span class="hljs-params">data</span>) =&gt;</span> b(data));
        }, first(...args));
    }
}
<span class="hljs-keyword">let</span> queue = <span class="hljs-keyword">new</span> AsyncSeriesWaterfallHook([<span class="hljs-string">&apos;name&apos;</span>]);
<span class="hljs-built_in">console</span>.time(<span class="hljs-string">&apos;cost&apos;</span>);
queue.tapPromise(<span class="hljs-string">&apos;1&apos;</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">name</span>) </span>{
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">resolve</span>) </span>{
        setTimeout(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
            <span class="hljs-built_in">console</span>.log(name, <span class="hljs-number">1</span>);
            resolve(<span class="hljs-number">1</span>);
        }, <span class="hljs-number">1000</span>);
    });
});
queue.tapPromise(<span class="hljs-string">&apos;2&apos;</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">data</span>) </span>{
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">resolve</span>) </span>{
        setTimeout(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
            <span class="hljs-built_in">console</span>.log(data, <span class="hljs-number">2</span>);
            resolve(<span class="hljs-number">2</span>);
        }, <span class="hljs-number">2000</span>);
    });
});
queue.tapPromise(<span class="hljs-string">&apos;3&apos;</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">data</span>) </span>{
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">resolve</span>) </span>{
        setTimeout(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
            <span class="hljs-built_in">console</span>.log(data, <span class="hljs-number">3</span>);
            resolve(<span class="hljs-number">3</span>);
        }, <span class="hljs-number">3000</span>);
    });
});
queue.promise(<span class="hljs-string">&apos;zfpx&apos;</span>).then(<span class="hljs-function"><span class="hljs-params">err</span> =&gt;</span> {
    <span class="hljs-built_in">console</span>.timeEnd(<span class="hljs-string">&apos;cost&apos;</span>);
});
</code></pre>
<h2 id="t2712. tapable">12. tapable <a href="#t2712. tapable"> # </a></h2>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> {Tapable,SyncHook} = <span class="hljs-built_in">require</span>(<span class="hljs-string">&quot;tapable&quot;</span>);
<span class="hljs-keyword">const</span> t = <span class="hljs-keyword">new</span> Tapable();
t.hooks = {
    <span class="hljs-attr">myHook</span>: <span class="hljs-keyword">new</span> SyncHook()
};
<span class="hljs-keyword">let</span> called = <span class="hljs-number">0</span>;
t.plugin(<span class="hljs-string">&quot;my-hook&quot;</span>, () =&gt; called++);
t.hooks.myHook.call();
t.plugin(<span class="hljs-string">&quot;my-hook&quot;</span>, () =&gt; called += <span class="hljs-number">10</span>);
t.hooks.myHook.call();
<span class="hljs-built_in">console</span>.log(called);
</code></pre>
<h2 id="t28&#x53C2;&#x8003;">&#x53C2;&#x8003; <a href="#t28&#x53C2;&#x8003;"> # </a></h2>
<ul>
<li><a href="https://github.com/alienzhou/webpack-internal-plugin-relation">webpack-internal-plugin-relation</a></li>
</ul>

        <div class="copyright">Powered by <a href="https://github.com/jaywcjlove/idoc" target="_blank">idoc</a>. Dependence <a href="https://nodejs.org">Node.js</a> run.</div>
    </div>
    
</div>

<script src="https://cdn.bootcss.com/jquery/3.0.0/jquery.js"></script>
<script>
$('.warpper .page-toc ul ul li a').on('click',function(){
  $('.warpper .page-toc ul ul li a').removeClass('my-active')
  $(this).addClass('my-active')
})
  // if (!$('.understand-me').length) {
  //   var bar = $(window).height() - $('.navbar ').height() - $('.page-toc').position().top;
  //   var count = bar / 26 / 2;
  //   var barHeight = $('.page-toc').outerHeight();
  //   $('.page-toc li').eq(0).children('a').addClass('red');
  //   var arr = [];
  //   $("h1,h2,h3,h4,h5,h6").each(function () {
  //     arr.push($(this).position().top);
  //   });
  //   var timer
  //   function dark() {
  //     clearTimeout(timer)
  //      timer = setTimeout(function () {
  //      var top = Math.abs($('.page-toc > ul').position().top);
  //      var cur = $('.content').scrollTop();
  //      for (var i = arr.length; i >= 0; i--) {
  //        if (arr[i] <= cur) {
  //          break;
  //        }
  //      }
  //      if (i === -1) {
  //        i = 0;
  //      }
  //      $('.page-toc li a').removeClass('red');
  //      $('.page-toc li').eq(i).children('a').addClass('red');
  //      let height = $('.page-toc li').eq(i).position().top-$('.page-toc').height(); // 如果当前的offset出去了 回到中间可好？
  //      $('.page-toc').scrollTop(height+$('.page-toc').height()/2);
  //    },200)
  //   }

  //   $('.content').on('scroll', dark);
  // }
</script>
<style>

    /* ::-webkit-scrollbar{width:14px;}
    ::-webkit-scrollbar-track{background-color:transparent;}
    ::-webkit-scrollbar-thumb{background-color:transparent;}
    ::-webkit-scrollbar-thumb:hover {background-color:transparent}
    ::-webkit-scrollbar-thumb:active {background-color:transparent} */

    .page-toc > ul .red {
        background: #f3f3f3;
        z-index: 1;
        border-left: 3px solid #009a61;
        -webkit-transition: all .2s ease;
        transition: all .2s ease;
        color: #000
    }





</style>
</body>
</html>
